import Opt from '@/components/dt/info/Opt.js'
import ruleOpt from '@/biz/option/rule.js'
import uploadOpt from '@/biz/option/upload.js'
import { Message } from 'view-design'

class UpdateOpt extends Opt {
  constructor(info) {
    super(info)
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '菜单名称',
        placeholder: '请输入菜单名称',
        key: 'menuName',
        input: {},
        // visible: this.info.type != 3,
        rules: [ruleOpt.required('请输入菜单名称'), ruleOpt.max(10)]
      },
      {
        title: '菜单code',
        placeholder: '请输入菜单code',
        key: 'menuCode',
        input: {},
        rules: [ruleOpt.required('请输入菜单code'), ruleOpt.max(20)]
      },
      {
        title: '菜单权重',
        placeholder: '请输入菜单权重',
        key: 'sort',
        input: {
          type: 'number',
          min: 1,
          max: 999
        },
        rules: [ruleOpt.required('请输入菜单权重', 'number'), ruleOpt.positiveInteger()]
      },
      uploadOpt.image(
        {
          title: '菜单图标',
          key: 'menuIcon',
          maxlength: 1,
          format: ['jpg', 'jpeg', 'png', 'gif'],
          visible: this.info.type != 3,
          rules: [ruleOpt.required('请选择菜单图标', 'array')]
        },
        this.info
      ),
      {
        visible: this.info.type != 3,
        title: '菜单角标',
        key: 'mark',
        group: [
          {
            col: 6,
            switch: {
              type: 'text',
              openText: 'New',
              closeText: 'New',
              size: 'large'
            },
            data: {
              from: (info) => info.mark == 1,
              to: (res) => {
                console.log(res)
                return { mark: res ? 1 : 0 }
              }
            }
          },
          {
            switch: {
              type: 'text',
              openText: 'Hot',
              closeText: 'Hot',
              size: 'large'
            },
            data: {
              from: (info) => info.mark == 2,
              to: (res) => ({ mark: res ? 2 : 0 })
            }
          }
        ]
      }
    ]
  }
}

export default UpdateOpt
